package com.xzm;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class SingletonTest {
    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        //得到构造函数
        Constructor<HungerySingleton> construcetor = HungerySingleton.class.getDeclaredConstructor();
        construcetor.setAccessible(true);
        HungerySingleton instance = construcetor.newInstance();
        HungerySingleton test = construcetor.newInstance();
        System.out.println("反射得到的对象："+test);
        System.out.println("单例得到的对象："+instance);
        System.out.println("两者一样否:"+(test==instance));
    }
}
